<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\File;

class ModulesServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        // 注册所有模块
    }

    /**
     * Bootstrap services.
     */
    public function boot(): void
    {
        // 为所有模块加载路由
        $this->loadModuleRoutes();
    }

    /**
     * 加载所有模块的传统路由文件
     */
    protected function loadModuleRoutes(): void
    {
        // 获取所有模块目录
        $modulesPath = base_path('Modules');
        if (!File::isDirectory($modulesPath)) {
            return;
        }
        
        // 加载每个模块的web.php路由文件
        foreach (File::directories($modulesPath) as $moduleDir) {
            $routePath = $moduleDir . '/routes/web.php';
            
            if (File::exists($routePath)) {
                $this->loadRoutesFrom($routePath);
            }
        }
    }
} 